package com.wzq.controller;



import com.wzq.dao.pojo.Code;
import com.wzq.dao.pojo.Place;
import com.wzq.dao.pojo.Result;
import com.wzq.service.IPlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yzc
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/doorproject")
public class DoorProjectController {

    @Autowired
    private IPlaceService iPlaceService;

    //    添加资源
    @PostMapping
    public Result save(@RequestBody Place place){
        boolean flag = iPlaceService.save(place);
        return new Result(flag? Code.SAVE_OK: Code.SAVE_ERR,flag);
    }

    //    删除资源
    @DeleteMapping
    public Result remove(@RequestBody List<Integer> ids) {
        boolean flag = iPlaceService.removeByIds(ids);
        return new Result(flag ? Code.DELETE_OK : Code.DELETE_ERR, flag);
    }
    //    修改资源
    @PutMapping
    public Result updateById(@RequestBody Place place) {
        boolean flag = iPlaceService.updateById(place);
        return new Result(flag? Code.UPDATE_OK:Code.UPDATE_ERR,flag);
    }
    //     获得所有成员
    @GetMapping
    public Result getAll() {
        List<Place> list = iPlaceService.list();
        Integer code = list != null ? Code.GET_OK : Code.GET_ERR;
        String msg = list != null ? "" : "数据查询失败，请重试！";
        return new Result(code,list,msg);
    }
}

